package vistasCasaCentral;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import RMIClient.RMIClientCSR;
import beans.ProveedorBean;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class JFrameBajaProveedor  extends javax.swing.JInternalFrame {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private static final long serialVersionUID = 1L;
	private JButton btnCancelar;
	private JLabel lblCUIT;
	private JTextField txtCUIT;
	private JButton btnAceptar;
	private static JFrameBajaProveedor instancia;
	
	public static JFrameBajaProveedor getInstancia(){
		if (instancia==null){
			instancia = new JFrameBajaProveedor();
		}
		return instancia;
	}
	
		
	public JFrameBajaProveedor() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setPreferredSize(new Dimension(400, 300));
			this.setBounds(0, 0, 400, 300);
			setVisible(true);
			getContentPane().setLayout(null);
			this.setTitle("Baja de proveedor");
			this.setSize(400, 150);
			{
				btnCancelar = new JButton();
				getContentPane().add(btnCancelar);
				btnCancelar.setText("Cancelar");
				btnCancelar.setBounds(218, 63, 107, 27);
				btnCancelar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						dispose();
					}
				});
			}
			{
				btnAceptar = new JButton();
				getContentPane().add(btnAceptar, "Center");
				btnAceptar.setText("Aceptar");
				btnAceptar.setBounds(64, 64, 98, 26);
				btnAceptar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						ProveedorBean proveedorBean = RMIClientCSR.getInstancia().buscarProveedor(txtCUIT.getText());
						if(proveedorBean.getCuit() != null && !"".equalsIgnoreCase(proveedorBean.getCuit())){
							if(RMIClientCSR.getInstancia().bajaProveedor(proveedorBean)){
								JOptionPane.showMessageDialog(JFrameBajaProveedor.getInstancia(),"Proveedor eliminado");
								dispose();
							}else{
								JOptionPane.showMessageDialog(JFrameBajaProveedor.getInstancia(),"El proveedor no pudo ser eliminado");
							}
						}else{
							JOptionPane.showMessageDialog(JFrameBajaProveedor.getInstancia(),"No existe proveedor para el CUIT seleccionado");
						}
					}
				});
			}
			{
				txtCUIT = new JTextField();
				getContentPane().add(txtCUIT);
				txtCUIT.setBounds(180, 27, 166, 21);
			}
			{
				lblCUIT = new JLabel();
				getContentPane().add(lblCUIT);
				lblCUIT.setText("Ingrese CUIT: ");
				lblCUIT.setBounds(60, 30, 73, 14);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
